using DealerPlatform.Core;
using DealerPlatform.Service.CustomerApp;
using DealerPlatform.Service.OrderApp;
using DealerPlatform.Service.OrderApp.Dtos;
using DealerPlatform.Web.Filters;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DealerPlatform.Web.Controllers;

[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[CtmAuthorizationFilter]
public class OrderInfoController(
    IOrderService orderService,
    ICustomerService customerService) : BaseController
{
    [HttpGet]
    public async Task<SaleOrderDto> GetSaleOrderDto(string orderNo)
    {
        return await orderService.GetOrderInfoByOrderNo(orderNo);
    }

    [HttpGet("orders")]
    public async Task<List<SaleOrderDto>> GetSaleOrders(string? sort,
        int pageIndex = 1,
        int pageSize = 30,
        OrderType orderTyp = OrderType.Asc)
    {
        return await orderService.GetSaleOrders(new PageWithSortDto()
        {
            Sort = sort,
            PageIndex = pageIndex,
            PageSize = pageSize,
            OrderType = orderTyp
        });
    }
}